#pragma once

#include "fxcc/core/graph/opengl3/font/pch.h"
#include "fxcc/core/graph/opengl3/Texture2DJack.h"
#include "fxcc/core/graph/opengl3/MeshJack.h"

namespace fxcc
{
    namespace graph
    {
        namespace opengl3
        {
            namespace font
            {
                struct FXCC_API  Character
                {
                    struct  Desc {

                        int m_FontSize;
                        wchar_t m_WChar;

                        bool operator<(const Desc& other) const {
                            return std::tie(m_FontSize, m_WChar) < std::tie(other.m_FontSize, other.m_WChar);
                        };
                        Desc() = default;

                        Desc(const int fontSize, const int _wchar) : m_FontSize(fontSize), m_WChar(_wchar)
                        {
                        }


                    };
                    std::shared_ptr<fxcc::graph::opengl3::Texture2DJack> m_Texture;

                    glm::ivec2 m_Size{ 0,0 };
                    glm::ivec2 m_Bearing;
                    glm::ivec2 m_Advance;

                    bool Avail() const
                    {
                        return m_Texture.get();
                    }
                    void BindTexture(int textMap)
                    {
                        m_Texture->Active(textMap);
                    }

                    std::vector<glm::vec3> NewPoss(glm::vec2 startPos) const
                    {
                        float x = startPos.x;
                        float y = startPos.y;
                        float scale = 1.0f;

                        GLfloat xpos = x + m_Bearing.x * scale;
                        GLfloat ypos = y - (m_Size.y - m_Bearing.y) * scale;

                        GLfloat w = m_Size.x * scale;
                        GLfloat h = m_Size.y * scale;

                        return  
                        {
                            glm::vec3(xpos, ypos + h, 0.0f),
                            glm::vec3(xpos, ypos, 0.0f),
                            glm::vec3(xpos + w, ypos, 0.0f),
                            glm::vec3(xpos + w, ypos + h, 0.f),
                        };
                    }
                };
            };
        };
    }
};